package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.OrderBean;
import com.project.bean.ShopBean;
import com.project.mapper.IOrderMapper;
import com.project.service.IOrderService;
import org.omg.CORBA.ORB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private IOrderMapper mapper;

    @Override
    public void add(OrderBean order, Map<Integer, ShopBean> shopMap) {
        mapper.addOrder(order);
        mapper.addOrderInfo(order.getId(),shopMap.values());
    }

    @Override
    public OrderBean findById(int id) {
        return mapper.findById(id);
    }

    @Override
    public PageInfo<OrderBean> findAllByUserId(int pagoNO,int userId) {
        PageHelper.startPage(pagoNO,PAGESIZE);
        PageInfo<OrderBean> pageInfo = PageInfo.of(mapper.findAllByUserId(userId));
        return pageInfo;
    }

    @Override
    public PageInfo<OrderBean> findAllByItem(int pagoNO, String status, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(pagoNO,PAGESIZE);
        PageInfo<OrderBean> pageInfo = PageInfo.of(mapper.findAllByItem(status,startDate,endDate));
        return pageInfo;
    }

    @Override
    public void updateState(int id, String state) {
        mapper.updateState(id,state);
    }
}
